﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Diagnostics;

namespace WindowsFormsApplication1.GameForms
{
    public partial class CricketSetup : Form
    {
        public CricketSetup()
        {
            InitializeComponent();
        }

        private void cmbPlayers_SelectedIndexChanged(object sender, EventArgs e)
        {

            Debug.WriteLine(cmbPlayers.SelectedIndex);
            switch (cmbPlayers.SelectedIndex)
            {

                case 3://4
                    txtPlayer4.Enabled = true;
                    goto case 2;
                case 2://3
                    txtPlayer3.Enabled = true;
                    if (cmbPlayers.SelectedIndex==2)
                    {
                        txtPlayer4.Enabled = false;
                        txtPlayer4.ResetText();
                    }
                    goto case 1;
                case 1://2
                    txtPlayer2.Enabled = true;
                    if(cmbPlayers.SelectedIndex==1)
                    {
                        txtPlayer3.Enabled=false;
                        txtPlayer3.ResetText();
                        txtPlayer4.Enabled = false;
                        txtPlayer4.ResetText();
                    }
                    goto case 0;
                case 0://1
                    txtPlayer1.Enabled = true;
                    if (cmbPlayers.SelectedIndex == 0)
                    {
                        txtPlayer2.Enabled = false;
                        txtPlayer2.ResetText();
                        txtPlayer3.Enabled = false;
                        txtPlayer3.ResetText();
                        txtPlayer4.Enabled = false;
                        txtPlayer4.ResetText();
                    }
                    break;

                default:
                    txtPlayer4.Enabled = false;
                    txtPlayer3.Enabled = false;
                    txtPlayer2.Enabled = false;
                    txtPlayer1.Enabled = false;
                    break;

            }
        }

        private void btnStart_Click(object sender, EventArgs e)
        {

            
            //
            // This shit doesn't work -- we need to pass in a game object that includes player names, etc
            // coming back from the form (back to BasePage) we can inspect the object and update names
            // other approach would be to fire events from this form back to BasePage.  Tried this numerous ways
            // can't access labels directly.
            //
            //switch (cmbPlayers.SelectedIndex)


            //{
            //    case 3://4
            //        blah.player4Name = (this.txtPlayer4.TextLength > 0 ? this.txtPlayer4.Text : "");
            //        goto case 2;
            //    case 2://3
            //        blah.player4Name = (this.txtPlayer3.TextLength > 0 ? this.txtPlayer3.Text : "");
            //        goto case 1;
            //    case 1://2
            //        blah.player2Name = (this.txtPlayer2.TextLength > 0 ? this.txtPlayer2.Text : "");
            //        goto case 0;
            //    case 0://1
            //        blah.lblPlayer1.Text = (this.txtPlayer1.TextLength > 0 ? this.txtPlayer1.Text : "");
            //        break;
            //    default:
            //        blah.player1Name = "";
            //        blah.player2Name = "";
            //        blah.player3Name = "";
            //        blah.player3Name = "";
            //        break;
                    
            //}
            //this.Close();
        }

        private void frmCricketSetup_Load(object sender, EventArgs e)
        {
            ResetControls();
        }
    
        private void ResetControls()
        {
            this.txtPlayer1.Text = "";
            this.txtPlayer2.Text = "";
            this.txtPlayer3.Text = "";
            this.txtPlayer4.Text = "";
            this.txtPlayer1.Enabled = false;
            this.txtPlayer2.Enabled = false;
            this.txtPlayer3.Enabled = false;
            this.txtPlayer4.Enabled = false;

            this.cmbPlayers.SelectedIndex = 0;
            this.chkPoints.Checked = true;
        }
    
    
    }
}